package com.mt.customer.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.customer.entity.CustomerAccountLogEntity;
import com.mt.customer.mapper.CustomerAccountLogEntityMapper;

@Component
public class CustomerAccountLogServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(CustomerAccountLogServiceModel.class);

    @Autowired
    private CustomerAccountLogEntityMapper customerAccountLogEntityMapper;

    public ServiceResult<List<CustomerAccountLogEntity>> selectList(Map<String, Object> params,
        PagerInfo<?> pagerInfo) {
        Assert.notNull(this.customerAccountLogEntityMapper, "Property 'customerAccountLogEntityMapper' is required.");
        ServiceResult<List<CustomerAccountLogEntity>> result = new ServiceResult<List<CustomerAccountLogEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }

            result.setResult(this.customerAccountLogEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[CustomerAccountLogServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<CustomerAccountLogEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.customerAccountLogEntityMapper, "Property 'customerAccountLogEntityMapper' is required.");
        ServiceResult<CustomerAccountLogEntity> result = new ServiceResult<CustomerAccountLogEntity>();
        try {
            result.setResult(this.customerAccountLogEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[CustomerAccountLogServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(CustomerAccountLogEntity customerAccountLogEntity) {
        Assert.notNull(this.customerAccountLogEntityMapper, "Property 'customerAccountLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.customerAccountLogEntityMapper.insert(customerAccountLogEntity);
            if (save > 0) {
                id = customerAccountLogEntity.getCustomerAccountLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[CustomerAccountLogServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(CustomerAccountLogEntity customerAccountLogEntity) {
        Assert.notNull(this.customerAccountLogEntityMapper, "Property 'customerAccountLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.customerAccountLogEntityMapper.updateByPrimaryKeySelective(customerAccountLogEntity);
            if (save > 0) {
                id = customerAccountLogEntity.getCustomerAccountLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[CustomerAccountLogServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(CustomerAccountLogEntity customerAccountLogEntity) {
        Assert.notNull(this.customerAccountLogEntityMapper, "Property 'customerAccountLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.customerAccountLogEntityMapper.updateByPrimaryKeySelective(customerAccountLogEntity);
            if (save > 0) {
                id = customerAccountLogEntity.getCustomerAccountLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[CustomerAccountLogServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer customerAccountLogId) {
        Assert.notNull(this.customerAccountLogEntityMapper, "Property 'customerAccountLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.customerAccountLogEntityMapper.deleteByPrimaryKey(customerAccountLogId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[CustomerAccountLogServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }
}
